<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
<title>Introduction to wxPython</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="wxPython, Introduction to wxPython, wxPython API, widgets">
<meta name="description" content="This part of the wxPython tutorial is an introduction to wxPython.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content">


<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>


<h1>Introduction to wxPython</h1>


<p>
An <b>application</b> is a computer program that performs a specific 
task or a group of tasks. Web browser, media player, word processor 
are examples of typical applications. A term <b>tool</b> or <b>utility</b> 
is used for a rather small and simple application that performs a single 
task. A unix cp program is an example of a such a tool. 
All these together form <b>computer software</b>. Computer software is 
the broadest term used to describe the operating system, data, computer
programs, applications, mp3 files or computer games. 
Applications can be created for four different areas.
</p>

<div class="center">
<img src="/img/gui/wxpython/areas.jpg" alt="Application areas">
</div>

<p>
Online shopping applications, wikis, weblogs are examples of popular web 
applications. They are accessed with a web browser.
Examples of desktop applications include Maya, Opera, Open Office or Winamp. 
Enterprise computing is a specific area. Applications in these area are 
complex and large. Applications created for portables include all programs 
developed for mobile phones, communicators, pdas and similar.
</p>

<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewSquare */
google_ad_slot = "0364418177";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 


<h2>Programming languages</h2>

<p>
There are currently several widely used programming languages. The 
following list is based on the 
<a href="http://www.tiobe.com/tpci.htm">TIOBE</a> Programming Community 
Index. The numbers are from November 2010. 
</p>

<table width="400">
<tr>
<th>Position</th>
<th>Language</th>
<th>Ratings</th>
</tr>
<tr>
<td>1</td><td>Java</td><td>18.5%</td>
</tr>
<tr class="gray">
<td>2</td><td>C</td><td>16.7%</td>
</tr>
<tr>
<td>3</td><td>C++</td><td>9.5%</td>
</tr>
<tr class="gray">
<td>4</td><td>PHP</td><td>7.8%</td>
</tr>
<tr>
<td>5</td><td>C#</td><td>5.7%</td>
</tr>
<tr class="gray">
<td>6</td><td>Python</td><td>5.7%</td>
</tr>
<tr>
<td>7</td><td>Visual Basic</td><td>5.5%</td>
</tr>
<tr class="gray">
<td>8</td><td>Objective C</td><td>3.2%</td>
</tr>
<tr>
<td>9</td><td>Perl</td><td>2.4%</td>
</tr>
<tr class="gray">
<td>10</td><td>Ruby</td><td>1.9%</td>
</tr>

</table>

<p>
Java is the most widely used programming language. Java excels in creating 
portable mobile applications, programming various appliances and in creating 
enterprise applications. Every fourth application is programmed in C/C++. 
They are standard for creating operating systems and various desktop applications. 
C/C++ are the most widely used system programming languages. Most famous desktop 
applications were created in C++. May it be MS Office, Macromedia Flash, Adobe Photoshop or 3D Max. 
These two languages also dominate the game programming business. 
</p>

<p>
PHP dominates over the Web. While Java is used mainly by large organizations, 
PHP is used by smaller companies and individuals. PHP is used to create dynamic 
web applications.  
</p>

<p>
C# is the main programming language of the Microsoft .NET platform. 
C# is followed in .NET by Visual Basic. It represents of the popularity
of the RAD. (Rapid Application Development.)
</p>

<p>
Perl, Python and Ruby are the most widely used scripting languages. They 
share many similarities. They are close competitors. 
</p>

<p>
The Objective C is the main programming language of the Apple ecosystem. 
</p>


<h2>Python</h2>

<p>
<img src="/img/gui/wxpython/pythonlogo.png" style="float:left" alt="python logo"> 
Python is a successful scripting language. It was initially developed by 
<b>Guido van Rossum</b>. It was first released in 1991. Python was inspired 
by ABC and Haskell programming languages. Python is a high level, general 
purpose, multiplatform, interpreted language. Some prefer to call it a 
dynamic language. It is easy to learn. Python is a minimalistic language. 
One of its most visible features is that it does not use semicolons nor 
brackets. Python uses indentation instead. Today Python is maintained by 
a large group of volunteers worldwide. 
</p>

<p>
For creating graphical user interfaces, python programmers can choose among 
three decent options. PyGTK, wxPython and PyQt.
</p>

<h2>wxPython</h2>

<p>
wxPython is a cross platform toolkit for creating desktop GUI applications. 
The principal author of wxPython is <b>Robin Dunn</b>. With wxPython developers can
create applications on Windows, Mac and on various Unix systems. 
wxPython is a wrapper around wxWidgets, which is a mature cross platform C++ 
library. wxPython consists of the five basic modules. 
</p>

<div class="center">
<img src="/img/gui/wxpython/modules.jpg" alt="wxPython modules">
</div>

<p>
<b>Controls</b> module provides the common widgets found in graphical applications. 
For example a Button, a Toolbar,  or a Notebook. Widgets are called controls under Windows OS. 
The <b>Core</b> module consists of elementary classes, that are used in development. 
These classes include the Object class, which is the mother of all classes, 
Sizers, which are used for widget layout, Events, basic geometry classses like 
Point and Rectangle. The Graphics Device Interface (<b>GDI</b>) is a set of 
classes used for drawing onto the widgets. This module contains classes for 
manipulation of Fonts, Colours, Brushes, Pens or Images. 
The <b>Misc</b> module contains of various other classes and module functions. 
These classes are used for logging, application configuration, system settings, 
working with display or joystick. The <b>Windows</b> module consists of various 
windows, that form an application. Panel, Dialog, Frame or Scrolled Window.
</p>

<h2>wxPython API</h2>

<p>
wxPython API is a set of methods and objects. Widgets are essential building 
blocks of a GUI application. Under Windows widgets are calles controls. We can 
roughly divide programmers into two groups. They code applications or libraries. 
In our case, wxPython is a library that is used by application programmers to 
code applications. Technically, wxPython is a wrapper over a C++ GUI API called 
wxWidgets. So it is not a native API. e.g. not written directly in Python. 
</p>

<p>
In wxPython we have lots of widgets. These can be divided into some logical groups. 
</p>

<h3>Base Widgets</h3>

<p>
These widgets provide basic functionality for derived widgets. They are called 
ancestors. They are usually not used directly. 
</p>

<img src="/img/gui/wxpython/base.jpg" alt="base widgets">
<br>

<h3>Top level Widgets</h3>

<p>
These widgets exist independently of each other.
</p>

<img src="/img/gui/wxpython/toplevel.jpg" alt="toplevel widgets">

<h3>Containers</h3>

<p>
Containers contain other widgets.
</p>


<img src="/img/gui/wxpython/containers.jpg" alt="containters">


<h3>Dynamic Widgets</h3>

<p>
These widgets can be edited by users. 
</p>

<img src="/img/gui/wxpython/dynamic.jpg" alt="dynamic widgets">


<h3>Static Widgets</h3>

<p>These widgets display information. They cannot be edited by user. </p>

<img src="/img/gui/wxpython/staticwidgets.jpg" alt="static widgets">


<h3>Other Widgets</h3>

<p>These widgets implement statusbar, toolbar and menubar in an application. </p>

<img src="/img/gui/wxpython/bars.jpg" alt="other widgets">


<h3>Inheritance</h3>

<p>
There is a specific relation among widgets in wxPython. This relation is developed 
by inheritance. The inheritance is a crucial part of the object oriented programming. 
Widgets form a hierarchy. Widgets can inherit functionality from other widgets. 
Existing classes are called base classes, parents, or ancestors. The widgets 
that inherit we call derived widgets,  child widgets or descendants. The terminology 
is borrowed from biology.
</p>

<img src="/img/gui/wxpython/inheritance.png" alt="inheritance diagram">
<div class="figure">Inheritance of a button</div>

<p>
Say we use a button widget in our application. The button widget 
inherits from 4 different base classes. 
The closest class is the <i>wx.Control</i> class. A button widget is
a kind of a small window. All widgets that appear on the screen are 
windows. Therefore they inherit from <i>wx.Window</i> class. There 
are objects that are invisible. Examples are sizers, device context 
or locale object. There are also classes that are visible but they 
are not windows. For example a color object, caret object or a cursor object. 
Not all widgets are controls. For example <i>wx.Dialog</i> is not a 
kind of control. The controls are widgets that are placed on other 
widgets called <b>containers</b>. That's why we have a separate <i>wx.Control</i> base class.  
</p>

<p>
Every window can react to events. So does the button widget. By clicking 
on the button, we launch the <i>wx.EVT_COMMAND_BUTTON_CLICKED</i> event. 
The button widget inherits the <i>wx.EvtHandler</i> via the <i>wx.Window</i> class.
Each widget that reacts to events must inherit from <i>wx.EvtHandler</i> class. 
Finally all objects inherit from <i>wx.Object</i> class. This is the Eve, 
mother of all objects in wxPython. 
</p>

<p>
This was an introduction to wxPython.
</p>

<div class="center"> 
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
</div>
<br>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="/wxpython">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified February 22, 2011  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>

